﻿using System;
using System.Diagnostics;

namespace LazyMapper.Tests.LazyMapper.Core
{
    public class DebugWatch
    {
        private DateTime _startTime;
        private bool _started;
        private TimeSpan _endTime;

        public DebugWatch()
        {
            Start();
        }

        public double TimeMilliseconds
        {
            get { return GetEndTime().TotalMilliseconds; }
        }

        public void Start()
        {
            _startTime = DateTime.Now;
            _started = true;
        }

        public void Stop()
        {
            _endTime = DateTime.Now - _startTime;
            _started = false;
        }


        public void Print(string name)
        {   
            TimeSpan endTime = GetEndTime();

            Debug.WriteLine(string.Format("{0} {1}", name, endTime));
        }

        public TimeSpan GetEndTime()
        {
            return _started ? (DateTime.Now - _startTime) : _endTime;
        }
    }
}